package com.traffic.between.redis.running;

import org.apache.log4j.Logger;

import com.traffic.between.annotation.ProvinderChoose;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.Redis;
import com.traffic.between.util.DictConstantKeys;
import com.traffic.between.util.OrderUtils;
import com.traffic.managent.service.order.bean.OrderBean;

/**
 * 接收订购中的订单  
 * 
 */
public class BsmOrderGoodsWorker implements Runnable, OrderUtils {

	private static Logger logger = Logger.getLogger(BsmOrderGoodsWorker.class);

	//只监听 0- 受理中 1-订购中两种状态
	public void run() {
		while (true) {
			
			OrderBean order = null;
			try {
				order = Redis.use(DictConstantKeys.redis_order_name).blpop(OrderUtils.ORDER_LIST_GOODS);
				if (order != null) {
					
					OrderInfoContext.putContext(order);
		
					if ("0".equals(order.getStatus())) {
						logger.info("BsmOrderGoodsWorker get to redis order id:" + order.getIds() + ",phoneNo:"
								+ order.getPhoneNo()+",Status:"+order.getStatus());
					
							ProvinderChoose.service.orderInvoke(order.getChannel());
						
						
					} else if ("1".equals(order.getStatus())){//订购中的往上游查询状态
						logger.info("BsmOrderStatusWorker get to redis order id:" + order.getIds() + ",phoneNo:"
								+ order.getPhoneNo()+",Status:"+order.getStatus());
						
							ProvinderChoose.service.statusInvoke(order.getChannel());
						
						
					}else {
						logger.info("BsmOrderStatusWorker get to redis order id:" + order.getIds() + ",phoneNo:"
								+ order.getPhoneNo()+",Status:"+order.getStatus());
					}
					OrderInfoContext.remove();
				}else {
					logger.info("get order from redis successfully! but it's null");
				}
				
			} catch (Exception e) {
				logger.error("BsmOrderGoodsWorker 线程处理队列中订单队列异常:" + e.getMessage(),e);
			}

		}
	}
}
